package com.qyer.search.storm.util;

import java.io.Serializable;
import java.util.*;

/**
 * Created by tangzheng on 16/1/8.
 */
public class KafkaMessage implements Serializable {
  private String _index;
  private String _type;
  private List<Integer> _entityIds;
  private int _stage;
  private long _time;

  public KafkaMessage() {
  }

  public KafkaMessage(String index, String type, List<Integer> entityIds, int stage){
    this._entityIds = entityIds;
    this._index = index;
    this._type = type;
    this._stage = stage;
  }

  public KafkaMessage(String _type, String _index, List<Integer> _entityIds, int _stage,
                      long time) {
    this._type = _type;
    this._index = _index;
    this._entityIds = _entityIds;
    this._stage = _stage;
    this._time = time;
  }

  public String get_index() {
    return _index;
  }

  public void set_index(String _index) {
    this._index = _index;
  }

  public List<Integer> get_entityIds() {
    return _entityIds;
  }

  public void set_entityIds(List<Integer> _entityIds) {
    this._entityIds = _entityIds;
  }

  public String get_type() {
    return _type;
  }

  public void set_type(String _type) {
    this._type = _type;
  }

  @Override public boolean equals(Object o) {
    if (this == o)
      return true;
    if (o == null || getClass() != o.getClass())
      return false;

    KafkaMessage that = (KafkaMessage) o;

    if (_index != null ? !_index.equals(that._index) : that._index != null)
      return false;
    if (_type != null ? !_type.equals(that._type) : that._type != null)
      return false;
    return !(_entityIds != null ? !_entityIds.equals(that._entityIds) : that._entityIds != null);

  }

  @Override public int hashCode() {
    int result = _index != null ? _index.hashCode() : 0;
    result = 31 * result + (_type != null ? _type.hashCode() : 0);
    result = 31 * result + (_entityIds != null ? _entityIds.hashCode() : 0);
    return result;
  }

  @Override public String toString() {
    return "KafkaMessage{" +
      "_index='" + _index + '\'' +
      ", _type='" + _type + '\'' +
      ", _entityIds=" + _entityIds +
      '}';
  }

  public int get_stage() {
    return _stage;
  }

  public void set_stage(int _stage) {
    this._stage = _stage;
  }

  public long get_time() {
    return _time;
  }

  public void set_time(long time) {
    this._time = time;
  }

  public int cost(long send){
    return (int)(send - this._time);
  }
}
